package memsim.instructions;
import memsim.SymbolTable;
import memsim.Alu;
import memsim.MemoryManager;
import memsim.RegisterHandler;
//import memsim.instructions;
/**
 *
 * @author kimchouSok
 * Execute class is executing instructions that depends on the opcodes
 */
public class Execute {

     static SymbolTable symbolTable = new SymbolTable();
    

     public static int getDecodeToExecute(DecodedObject opObject, Alu alu, MemoryManager m, RegisterHandler rH){
        if(!opObject.isEmpty())
        {
            int temp;
            int dstReg = opObject.getDstReg();
            temp = opObject.getOpCode();//decode.ShiftOpcode(opObject.getSrcReg1());
            System.out.println("op: " + temp);
            symbolTable.table();
            symbolTable.map.get(temp);
            if((symbolTable.map.get(temp)).equals("ADDS")){
               rH.setValue(dstReg, alu.adds.addScalar(rH.getValue(opObject.getSrcReg1()), rH.getValue(opObject.getSrcReg2())));
               alu.updateCycle(3);
               System.out.println("add");
               System.out.println(dstReg);
            }
            else if((symbolTable.map.get(temp)).equals("ANDS")){
                rH.setValue(dstReg, alu.ands.andScalar(opObject.getSrcReg1(), opObject.getSrcReg2()));
                alu.updateCycle(3);
                System.out.println("and");
            }
            else if((symbolTable.map.get(temp)).equals("NOTS")){
                rH.setValue(dstReg, alu.nots.notScalar(opObject.getSrcReg1()));
                alu.updateCycle(2);
                System.out.println("not");
            }
            else if((symbolTable.map.get(temp)).equals("ORS")){
                rH.setValue(dstReg, alu.ors.orScalar(opObject.getSrcReg1(), opObject.getSrcReg2()));
                alu.updateCycle(3);
                System.out.println("or");
            }
            else if((symbolTable.map.get(temp)).equals("SUBS")){
                rH.setValue(dstReg, alu.subs.subScalar(opObject.getSrcReg1(), opObject.getSrcReg2()));
                alu.updateCycle(3);
                System.out.println("sub");
            }
            else if ((symbolTable.map.get(temp)).equals("BR")){
               alu.br.unConditionalBr(opObject.getDstReg(), rH);
               alu.updateCycle(2);
               System.out.println("br");
            }
            else if ((symbolTable.map.get(temp)).equals("STRS")){
               alu.strs.storeInMemory(opObject.getDstReg(), opObject.getSrcReg1(), m, rH);
               alu.updateCycle(100);
               System.out.println("str");
            }
            else if ((symbolTable.map.get(temp)).equals("LDR")){
               alu.ldr.loadRegister(opObject.getDstReg(), opObject.getSrcReg1(), rH, m);
               alu.updateCycle(100);
               System.out.println("ld");
            }
        }
         return 0;

    }


}
